/*************************************************
Author: tony
Date: 12/11/2012
Description:
Notes:
*************************************************/

#ifndef __CClanConfig_h__
#define __CClanConfig_h__

#include "commerrno.h"
#include "commclass.h"
#include "CTSizeString.h"
#include "CTHashObjectMgr.h"

class CClanBuildConfig
{
public:
    CClanBuildConfig ()
    {
        _bconfigured = false;
        _iConstructionCost = 0;
        _shExpAddtion = 0;
        _shSilverAddtion = 0;
    }

    bool _bconfigured;  //是否已经配置过
    int  _iConstructionCost;  //升级所需建设度
    short  _shExpAddtion;     //经验提升千分比
    short  _shSilverAddtion;   //经验提升千分比
    unsigned char  _ucShopItemCnt;   //家族商店可出售物品数
};

class CClanSkillConfig
{
public:
    CClanSkillConfig () : _bconfigured(false)
    {
        _ucSkillId = 0;
        _ucAttrType = 0;
        _shPerAttrValue = 0;
    }

    bool _bconfigured;  //是否已经配置过
    unsigned char _ucSkillId;   //技能ID
    unsigned char _ucAttrType;  //技能对应的属性类型
    short  _shOpenLevel;        //开放等级
    short  _shPerAttrValue;     //每级提升的属性值    
};

//学习家族技能需要的贡献度
class CSkillContriConfig
{
public:
    CSkillContriConfig ()
    {
        _astNeedContri.m_iUsedCount = MAX_CLAN_SKILL_NUM + 1;
        for (int i = 0; i < _astNeedContri.Size(); i++)
        {
            _astNeedContri[i] = 0;
        }
    }

    int AddContriCost (unsigned char ucSkillId, int iContriCost)
    {
        if (0 != _astNeedContri[ucSkillId] 
            || 0 == ucSkillId || 0 == iContriCost)
        {
            return ERROR_CLAN_SKILL_CONFIG;
        }

        _astNeedContri[ucSkillId] = iContriCost;
        return 0;
    }

    CTArray<int, MAX_CLAN_SKILL_NUM+1> _astNeedContri;
};


class CClanConfigData
{
public:
	CClanConfigData()
    {
        _stClanBuild.m_iUsedCount = MAX_CLAN_LEVEL + 1;
        _stClanSkill.m_iUsedCount = MAX_CLAN_SKILL_NUM + 1;
        _stSkillContri.m_iUsedCount = MAX_CLAN_SKILL_LEVEL;
	}

	virtual ~CClanConfigData()
    {
	}

    int AddClanBuildConfig (int iClanLevel, CClanBuildConfig & stConfigData)
    {
        if ((iClanLevel < 0 || iClanLevel > MAX_CLAN_LEVEL || stConfigData._ucShopItemCnt > MAX_CLAN_SHOP_ITEM)
             || (_stClanBuild[iClanLevel]._bconfigured))
        {
            CT_ERROR (("iClanLevel: %u", iClanLevel));
            return ERROR_CLAN_BUILD_CONFIG;
        }

        stConfigData._bconfigured = true;
        _stClanBuild[iClanLevel] = stConfigData;
        return 0;
    }

    int GetClanBuildConfig (int iClanLevel, CClanBuildConfig & stConfigData)
    {
        if ((iClanLevel < 0 || iClanLevel > MAX_CLAN_LEVEL)
            || (!_stClanBuild[iClanLevel]._bconfigured))
        {
            CT_ERROR (("iClanLevel: %u", iClanLevel));
            return ERROR_CLAN_BUILD_CFG_NONE;
        }

        stConfigData = _stClanBuild[iClanLevel];
        return 0;
    }

    int AddSkillConfig (unsigned char ucSkillId, CClanSkillConfig & stConfigData)
    {
        if ((ucSkillId < 0 || ucSkillId > MAX_CLAN_SKILL_NUM)
            || (_stClanSkill[ucSkillId]._bconfigured))
        {
            CT_ERROR (("ucSkillId: %u", ucSkillId));
            return ERROR_CLAN_SKILL_CONFIG;
        }

        stConfigData._bconfigured = true;
        _stClanSkill[ucSkillId] = stConfigData;
        return 0;
    }

    int GetSkillConfig (unsigned char ucSkillId, CClanSkillConfig & stConfigData)
    {
        if ((ucSkillId < 0 || ucSkillId > MAX_CLAN_SKILL_NUM)
            || (!_stClanSkill[ucSkillId]._bconfigured))
        {
            CT_ERROR (("ucSkillId: %u", ucSkillId));
            return ERROR_CLAN_SKILL_CONFIG;
        }

        stConfigData = _stClanSkill[ucSkillId];
        return 0;
    }

    int AddSkillContriConfig (unsigned char ucSkillLevel, CSkillContriConfig & stConfigData)
    {
        if (ucSkillLevel >= MAX_CLAN_SKILL_LEVEL)
        {
            CT_ERROR (("ucSkillLevel: %u", ucSkillLevel));
            return ERROR_CLAN_SKILL_CONFIG;
        }

        _stSkillContri[ucSkillLevel] = stConfigData;
        return 0;
    }

    int GetLearnSkillContri (unsigned char ucSkillId, unsigned char ucSkillLevel, int & iContriCost)
    {
        if (ucSkillLevel >= MAX_CLAN_SKILL_LEVEL || ucSkillId > MAX_CLAN_SKILL_NUM || 0 == ucSkillId)
        {
            CT_ERROR (("ucSkillLevel: %u, %d", ucSkillLevel, ucSkillId));
            return ERROR_CLAN_SKILL_CONFIG;
        }

        iContriCost = _stSkillContri[ucSkillLevel]._astNeedContri[ucSkillId];
        return 0;
    }

    bool IsSkillOpen (short shClanLevel, unsigned char ucSkillId)
    {
        CClanSkillConfig stConfigData;
        int iRet = GetSkillConfig (ucSkillId, stConfigData);
        if(iRet)
        {
            return false;
        }

        if (stConfigData._shOpenLevel > shClanLevel)
        {
            return false;
        }

        return true;
    }


    CTArray<CClanBuildConfig, MAX_CLAN_LEVEL + 1> _stClanBuild;
    CTArray<CClanSkillConfig, MAX_CLAN_SKILL_NUM + 1> _stClanSkill;
    CTArray<CSkillContriConfig, MAX_CLAN_SKILL_LEVEL> _stSkillContri;
};


#endif // __CClanConfig_h__

